package com.xs.ahoi.hcxs.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Window;
import android.view.WindowManager;

import butterknife.ButterKnife;

import com.xs.ahoi.hcxs.Ahoi;
import com.xs.ahoi.hcxs.utils.MeasureUtil;

/**
 * 弹窗页面
 */
public abstract class BaseDialog extends Dialog {

    public abstract int getLayoutRes();

    protected abstract void initData();

    protected abstract int showPosition();

    protected void initListener() {

    }

    public BaseDialog(@NonNull Context context) {
        super(context);
    }

    public BaseDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(getLayoutRes());
        ButterKnife.bind(this);

        // 设置弹窗位置
        Window window = getWindow();
        if (window != null) {
            window.setGravity(showPosition());

            // 设置弹窗宽度
            WindowManager.LayoutParams p = window.getAttributes();
            Activity activity = Ahoi.getInstance().getActivity();
//            p.height = (int) (MeasureUtil.getScreenHeight(activity) * 0.75);
            p.width = MeasureUtil.getScreenWidth(activity);
            window.setAttributes(p);
        }

        initData();
        initListener();
    }

}
